package com.dougmccune.containers
{
	import mx.containers.BoxDirection;
	import mx.containers.Box;
	import mx.core.mx_internal;
	import mx.skins.halo.TabSkin;
	import mx.core.EdgeMetrics;
	
	use namespace mx_internal;
	
	[ExcludeClass]
	
	[Style(name="horizontalGap", type="Number", format="Length", inherit="no")]
	
	public class VerticalTabNavigator extends SuperTabNavigator
	{
		public function VerticalTabNavigator()
		{
			super();
		}
		
		override protected function createChildren():void {
			super.createChildren();

			tabBar.direction = BoxDirection.VERTICAL;
			tabBar.setStyle("verticalGap", this.getStyle("verticalGap"));
			
			
			
			holder.direction = BoxDirection.VERTICAL;
	        	
	       	holder.setStyle("verticalGap", 0);
	       	holder.setStyle("horizontalGap", 0);
	        holder.verticalScrollPolicy = "off";
	        
	        holder.setStyle("horizontalAlign", "right");
	        holder.swapChildren(canvas, popupButton);
	      
	        	
		}
		
		override protected function get contentY():Number
	    {
	        var paddingTop:Number = getStyle("paddingTop");
	
	        if (isNaN(paddingTop))
	            paddingTop = 0;
	
	        return paddingTop;
	    }
	    
	   override protected function get contentX():Number
	    {
	        var paddingLeft:Number = getStyle("paddingLeft");
	
	        if (isNaN(paddingLeft))
	            paddingLeft = 0;
	
	        return tabBarWidth + paddingLeft;
	    }
	    
	     private function get tabBarWidth():Number
	    {
	        var tabWidth:Number = getStyle("tabWidth");
	
	        if (isNaN(tabWidth))
	            tabWidth = tabBar.getExplicitOrMeasuredWidth();
	
	        return tabWidth - 1;
	    }
	    
	    override protected function get tabBarHeight():Number
	    {
	        var tabHeight:Number = tabBar.getExplicitOrMeasuredHeight();
	
	        return tabHeight;
	    }
	    
	   
    
    	override protected function updateDisplayList(unscaledWidth:Number,
                                                  unscaledHeight:Number):void
	    {
	        super.updateDisplayList(unscaledWidth, unscaledHeight);
	        
	
	        var vm:EdgeMetrics = viewMetrics;
	        var w:Number = unscaledWidth - vm.left - vm.right;
	
	        var tw:Number = tabBarWidth + 1;
	        var ph:Number = tabBar.getExplicitOrMeasuredHeight();
	        
	         
	        
	        holder.move(0, 0);
	        holder.setActualSize(tw, unscaledHeight);
	       
           
           	var canvasWidth:Number = tw;
			
			canvas.width = canvasWidth;
			
			tabBar.setActualSize(tw, unscaledHeight);
			
			menu.maxHeight = unscaledHeight - popupButton.height;
			
			
	    }
	    
    
		override protected function layoutChrome(unscaledWidth:Number,
                                             unscaledHeight:Number):void
	    {
	        super.layoutChrome(unscaledWidth, unscaledHeight);
	
	        // Move our border so it leaves room for the tabs
	        if (border)
	        {
	            var borderOffset:Number = tabBarWidth;
	            border.setActualSize(unscaledWidth - borderOffset, unscaledHeight);
	            border.move(borderOffset, 0);
	        }
	    }
	}
}